home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / LISTINGS / V_13_07 / ROSS.ZIP / TEST.C < prev   
Encoding:
C/C++ Source or Header  |  1995-05-02  |  946 b   |  39 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #define MB 400000
  6. #define MP 256
  7. #define NCOPY 3
  8. char *txtbuf;
  9. int xxxFind(int n, char *txt, int m, char *pat);
  10. main(int argc, char **argv)
  11. {
  12.   char patbuf[MP];
  13.   FILE *in;
  14.   int i, m, n, t0, t1;
  15.   int nmatch = 0;
  16.   if (argc < 3)
  17.   { fprintf(stderr,"usage: %s pattern file\n",argv[0]);
  18.     exit(0);
  19.   }
  20.   if ((in = fopen(argv[2], "r")) == NULL)
  21.   { fprintf(stderr,"cannot open input file: %s\n",argv[2]);
  22.     exit(0);
  23.   }
  24.   strcpy(patbuf, argv[1]);
  25.   m = strlen(patbuf);
  26.   txtbuf = malloc(NCOPY*MB);
  27.   n = 0;
  28.   for (i=0; i<NCOPY; i++)
  29.   { n += fread(txtbuf+n, sizeof(char), MB, in);
  30.     rewind (in);
  31.   }
  32.   close(in);
  33.   t0 = clock();
  34.   nmatch = xxxFind(n, txtbuf, m, patbuf);
  35.   t1 = clock() - t0;
  36.   printf("%d matches took %.3f\n", nmatch, (float)t1/CLOCKS_PER_SEC);
  37. }
  38. Figure 2. Main program for testing string searching functions.
  39.